﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CF.Data.Entity.FrmMemberEntity;

namespace CF.Member.DAL.Badges
{
    /// <summary>
    /// 初出茅庐徽章
    /// </summary>
    public class NewHandBadge : BaseBadge
    {
        public NewHandBadge() : base(0, 0, 1, 1) { }

        public override bool CheckTakeCondition(int uid, int bid)
        {
            bool result = false;
            if (base.CheckTakeCondition(uid, bid))
            {
                using (caifendbEntities context = new caifendbEntities())
                {
                    int count = context.FM_CostHistory.Count(c => c.UID == uid);
                    if (count > 0)
                    {
                        FM_BadgeConfig bdcfg = context.FM_BadgeConfig.FirstOrDefault(c => c.BID == bid);
                        if (bdcfg != null)
                        {
                            int param;
                            if (!int.TryParse(bdcfg.CheckParam, out param))
                            {
                                param = 1;
                            }
                            if (count >= param)
                            {
                                result = true;
                            }
                        }
                    }
                }
            }
            return result;
        }
    }
}
